const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')

const { ModuleFederationPlugin } = webpack.container

module.exports = defineConfig({
  publicPath: 'auto',
  transpileDependencies: true,
  configureWebpack: {
    output: {
      uniqueName: 'app1',
    },
    optimization: {
      splitChunks: {
        cacheGroups: {
          defaultVendors: {
            name: "chunk-vendors",
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            chunks: "async",
            reuseExistingChunk: true,
          },
          common: {
            name: "chunk-common",
            minChunks: 2,
            priority: -20,
            chunks: "async",
            reuseExistingChunk: true,
          },
        },
      },
    },
    plugins: [
      new ModuleFederationPlugin({
        name: 'app1',
        filename: 'remoteEntry.js',
        library: { type: "var", name: "app1" },
        exposes: {
          './routes_app1': './src/router/routes.js',
          './messages_app1': './src/lang/messages.js'
        },
        shared: {
          vue: {
            requiredVersion: '^3.2.13',
            eager: true
          }
        }
      })
    ]
  }
})
